//
//  LGShotr.m
//  lgdw
//
//  Created by Apple on 15/12/11.
//  Copyright © 2015年 Apple. All rights reserved.
//

#import "LGShotr.h"

@implementation LGShotr
+ (instancetype)shotrWithDict:(NSDictionary *)dict {
    LGShotr *shotr = [[self alloc] init];
    
    [shotr setValuesForKeysWithDictionary:dict];
    return shotr;
}
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}
+ (void)shotrListWithSuccessBlock:(void (^)(NSArray *))successBlock errorBlock:(void (^)(NSError *))errorBlock {
    NSDictionary *parameter =
    // 未登录获取的数据
//        @{@"Appid":@"10000024",
//          @"Appkey":@"e93b6295c8143f2805c2c3013390d344",
//          @"act":@"lists",
//          @"client_ver":@"1.2.1",
//          @"mid":@"0feab903c30b8d91f8ba9d46c153e1de93c2055e",
//          @"page":@"0",
//          @"platform":@"iPhone9.1",
//          @"yd_auth":@"",
//          @"yd_key":@"",
//          @"yd_uid":@""};
    // 登陆
    @{@"Appid":@"10000024",
      @"Appkey":@"e93b6295c8143f2805c2c3013390d344",
      @"act":@"lists",
      @"client_ver":@"1.2.1",
      @"mid":@"e553e2d24021fb8a156296b27e95fe3e4cf40791",
      @"page":@"0",
      @"platform":@"iPhone9.1",
      @"yd_auth":@"d4f6ZD7td1cA6eH0SFATxSF07DKOXB%2B7gHKhfLtmV8FYgoK%2BUm4Wp%2FCaZti6tWV75B%2FtEtCn12jixPPuZvdHoYAe%2FFntpIYn2dLpN89taV3K1vhT3Q%2BBDBixLRwmKZwel%2BXn",
      @"yd_key":@"9563klroXuyAUEc61OJWViLHGR%2BCzHgbhYmyhwkZYSJ3",
      @"yd_uid":@"7014"};
    [[LGNetworkTools sharedManager] POST:@"/short" parameters:parameter success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *responseObject) {
        NSArray *array = responseObject[@"data"];
        
        // 字典转模型
        NSMutableArray *mArray = [NSMutableArray arrayWithCapacity:10];
        [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            LGShotr *shotr = [LGShotr shotrWithDict:obj];
            [mArray addObject:shotr];
        }];
        
        if (successBlock) {
            successBlock(mArray.copy);
        }
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (errorBlock) {
            NSLog(@"LGDiscover错误%@",error);
            
        }
    }];

}
@end
